-- ConVar Extension
-- by Pennerlord
E2Lib.RegisterExtension("convar", false)


local function canCreateConVar(self)
	local ply = self.player
	if not ply:IsValid() then return false end
	if ply:GetInfoNum("wire_expression2_concmd") == 0 then return false end
	
	return true
end

local function createConVar(self, name, default, ShouldSave, userdata)
	default = default or ""
	ShouldSave = tobool(ShouldSave) or false
	userdata = tobool(userdata) or false
	
	if not canCreateConVar(self) then return end
	
	-- Send the information to the client as we can only create the convar there
	umsg.Start("wire_expression2_create_convar", self.player)
		umsg.String(name)
		umsg.String(default)
		umsg.Bool(ShouldSave)
		umsg.Bool(userdata)
	umsg.End()
end


--[[----------------------------------------------------
		E2 Functions
------------------------------------------------------]]

--[[----------------------------------------------------
		Create ConVar
------------------------------------------------------]]
e2function void convarCreate(string Name)
	createConVar(self, Name)
end

e2function void convarCreate(string Name, string DefaultValue)
	createConVar(self, Name, DefaultValue)
end

e2function void convarCreate(string Name, string DefaultValue, ShouldSave)
	createConVar(self, Name, DefaultValue, ShouldSave)
end

e2function void convarCreate(string Name, string DefaultValue, ShouldSave, SendToServer)
	createConVar(self, Name, DefaultValue, ShouldSave, SendToServer)
end